<?php

namespace addons\unidrink\model;

use think\Db;
use think\Model;
use traits\model\SoftDelete;

/**
 * @property int $product_id
 */
class ScoreOrder extends Model
{
    use SoftDelete;

    // 表名
    protected $name = 'unidrink_score_order';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 订单状态
    const STATUS_NORMAL = 1; // 正常
    const STATUS_CANCEL = 0; // 用户取消订单

    public function product()
    {
        return $this->belongsTo('scoreProduct', 'product_id');
    }

    /**
     * 订单状态
     * @param $order
     */
    public function orderStatusText($order)
    {
        if ($order['status'] == self::STATUS_CANCEL) {
            return '已取消';
        }
        $return = '无';
        if ($order['have_paid'] > 0) {
            $return = '待发货';
        }
        if ($order['have_delivered'] > 0) {
            $return = '已发货';
        }
        if ($order['have_received'] > 0) {
            $return = '已完成';
        }
        return $return;
    }


}